﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrokerBase.Lib.Policy;
using BrokerBase.Lib.Product;

namespace broker.duty.YG
{
    public class ProductExpander : AbstractProductExpander
    {
        /// <summary>
        /// 保单加载完成
        /// </summary>
        /// <param name="policy"></param>
        public override bool InitPolicy(IPolicy policy,out string msg)
        {
            try
            {
                policy.Amount = policy.Owner.BasicPolicy.Amount;

                IPaymentPeriod bpp = policy.Owner.BasicPolicy.SelectedPaymentPeriod;

                policy.SelectedPaymentPeriod = policy.Product.PaymentPeriods.First(p => p.Style == bpp.Style && p.Value == bpp.Value);

                IInsurancePeriod ipp = policy.Owner.BasicPolicy.SelectedInsurancePeriod;

                policy.SelectedInsurancePeriod = policy.Product.InsurancePeriods.First(p => p.Style == ipp.Style && p.Value == ipp.Value);

                policy.SelectedRowRateFactors["领取年龄"] = policy.Owner.BasicPolicy.SelectedRowRateFactors["领取年龄"];

                policy.SetSettingLock("Amount", true);
                policy.SetSettingLock("领取年龄", true);
                policy.SetSettingLock("缴费期限", true);

                policy.Amount = policy.Owner.Policies.Sum(p => p.TotalFee);


                policy.Amount = policy.Owner.BasicPolicy.Fee;
                msg = string.Empty;
                return true;
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return false;
            }

            
        }

    }
}
